package com.medium.house.service.impl;

import com.medium.house.entity.HouseBanner;
import com.medium.house.repository.HouseBannerMapper;
import com.medium.house.response.HousePicsDto;
import com.medium.house.service.HouseBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : wang.yu
 * @Description :
 * @Date: Created in 2018/3/5 0005  14:47
 * @Modified By
 */
@Service
public class HouseBannerServiceImpl implements HouseBannerService {

    @Autowired
    private HouseBannerMapper houseBannerMapper;

    @Override
    public int add(HouseBanner dto)
    {
        return houseBannerMapper.insert(dto);
    }

    @Override
    public int delete(long id)
    {
        return houseBannerMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(HouseBanner dto)
    {
        return houseBannerMapper.updateByPrimaryKeySelective(dto);
    }

    @Override
    public HouseBanner get(long id)
    {
        return houseBannerMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<HouseBanner> getByPage(
            int start,
            int limit,
            int orderby,
            int order,
            int status)
    {
        if (start < 0) {start = 0;}
        if (limit <=0) {limit = 20;}
        if (orderby > HouseBannerMapper.ORDERBY.length - 1 || orderby < 0) {orderby = 0;}
        if (order != 0) {order = 1;}

        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return houseBannerMapper.selectByPage(start, limit, HouseBannerMapper.ORDERBY[orderby], HouseBannerMapper.ORDER[order], args);
    }

    @Override
    public List<Long> getIdsByPage(
            int start,
            int limit,
            int orderby,
            int order)
    {
        if (start < 0) {start = 0;}
        if (limit <=0) {limit = 20;}
        if (orderby > HouseBannerMapper.ORDERBY.length - 1 || orderby < 0) {orderby = 0;}
        if (order != 0) {order = 1;}

        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return houseBannerMapper.selectIdsByPage(start, limit, HouseBannerMapper.ORDERBY[orderby], HouseBannerMapper.ORDER[order], args);
    }

    @Override
    public long count()
    {
        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return houseBannerMapper.count(args);
    }
    @Override
    public List<HousePicsDto> getAllBanner(int status){
        Map<String, Object> args = new HashMap<>();
        args.put("status",status);
        return houseBannerMapper.selectAllBanner(args);
    }
}
